export class WordCounter {
    private clean(text: string): string {
        return text.replace(/^#.*$/gm, '').trim();
    }

    public count(text: string): number {
        const cleaned = this.clean(text);
        if (cleaned.length === 0) {
            return 0;
        }

        const enRegex = new RegExp(/\b[A-Za-z0-9]+['-_]?[A-Za-z0-9]*\b/g);
        const enWords = (cleaned.match(enRegex) || []).length;
        const cjkRegex = new RegExp(/[\u4E00-\u9FFF\u3000-\u303F\uFF01-\uFF65\u2010-\u2013\u2016-\u205F\uFE10-\uFE4F\u00B7\u2E80-\u2EFF]/gu);
        const cjkWords = (cleaned.match(cjkRegex) || []).length;
        const dashRegex = new RegExp(/——/g);
        const dashWords = (cleaned.match(dashRegex) || []).length;

        return cjkWords + enWords + dashWords;
    }
}